<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="优惠券订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponNo">
              <a-input v-model="model.couponNo" placeholder="请输入优惠券订单号"  ></a-input>
            </a-form-model-item>
          </a-col>
            <a-col :span="12">
            <a-form-model-item label="优惠券名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponName">
              <a-input v-model="model.couponName" placeholder="请输入优惠券名称"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="优惠券类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponType">
                <a-radio-group v-model="model.couponType">
                  <a-radio :value="1">折扣券</a-radio>
                  <a-radio :value="2">代金券</a-radio>
                </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="使用状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useStatus">
                <a-radio-group v-model="model.useStatus">
                  <a-radio :value="0">未使用</a-radio>
                  <a-radio :value="1">已核销</a-radio>
                  <a-radio :value="2"> 已过期</a-radio>
                </a-radio-group>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="所属商家" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="merchName">
              <a-input v-model="model.merchName" placeholder="请输入商家名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属会员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userPhone">
              <a-input :value="model.userName+model.userPhone" placeholder="请输入会员手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="劵码有效期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="validBeginTime">
              <a-range-picker  v-model="dateRangeFC" 
                format="YYYY-MM-DD"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="支付金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="advancePurchasePrice">
              <a-input-number v-model="model.advancePurchasePrice" placeholder="请输入提前购买价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          
        </a-row>
         <a-row>
          <a-col :span="12">
            <a-form-model-item label="领取时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveDate">
              <a-input placeholder="请选择领取时间" v-model="model.receiveDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
           <a-col :span="12">
            <a-form-model-item label="核销时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkDate">
              <a-input :placeholder="model.checkDate==null?'未核销':model.checkDate" v-model="model.checkDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      
        
       
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="核销人手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkUser">
              <a-input v-model="model.checkUser" placeholder="请输入核销手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
          <a-col :span="24">
            <a-form-model-item label="券使用规则" :labelCol="{ xs: { span: 24 },sm: { span: 2 },}" :wrapperCol="{xs: { span: 24 }, sm: { span: 20 },}" prop="useDesc">
              <a-textarea v-model="model.useDesc" rows="4"  />
            </a-form-model-item>
          </a-col>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
import moment from 'moment'
  export default {
    name: 'AdhCouponOrderForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        dateRangeFC:[],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/couponOrder/adhCouponOrder/add",
          edit: "/couponOrder/adhCouponOrder/edit",
          queryById: "/couponOrder/adhCouponOrder/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
        this.dateRangeFC = [
                moment(this.model.validBeginTime, this.dateFormat),
                moment(this.model.validEndTime, this.dateFormat)
        ]
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'post';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>